package com.hh.bss.customer.convertor;

import java.util.ArrayList;
import java.util.List;

import com.hh.bss.common.TreeNodeDTO;
import com.hh.bss.talent.entity.CvFolderType;


public class ExtJsConvertor {
	public static TreeNodeDTO toTreeNodeDto(CvFolderType folderType){
		TreeNodeDTO treeNodeDto = new TreeNodeDTO();
		treeNodeDto.setId(folderType.getId().toString());
		treeNodeDto.setText(folderType.getName());
		treeNodeDto.setLeaf(folderType.getChildren()==null);
		
		if(treeNodeDto.isLeaf()){
			treeNodeDto.setChildren(null);
		}else{
			List<TreeNodeDTO> childrenTreeNodes = new ArrayList<TreeNodeDTO>();
			for(CvFolderType tmp:folderType.getChildren()){
				childrenTreeNodes.add(toTreeNodeDto(tmp));
			}
			treeNodeDto.setChildren(childrenTreeNodes);
		}
		
		return treeNodeDto;
		
	}
	
	public static TreeNodeDTO toTreeNodeDto(List<CvFolderType> folders ){
		TreeNodeDTO root = new TreeNodeDTO();
		root.setId("-1");
		root.setText("ROOT");
		root.setLeaf(false);
		
		if(folders == null){
			root.setChildren(null);
			
		}
		
		List<TreeNodeDTO> children = new ArrayList<TreeNodeDTO>();
		for(CvFolderType folder:folders){
			children.add(toTreeNodeDto(folder));
		}
		root.setChildren(children);
		return root;
		
	}

}
